<?php

namespace app\controllers;

use app\models\Sessions;
use app\models\Admins;

use lithium\security\Auth;
use lithium\action\DispatchException;

class SessionsController extends \lithium\action\Controller {

	#public function view() {
	#	$session = Sessions::first($this->request->id);
	#	return compact('session');
	#}

	public function add() {

		if (Auth::check('default', $this->request)) {
			return $this->redirect('/');
		} else {
			$admin = Admins::create($this->request->data);
			if ($this->request->data) {
				$result = "Could not successfully log in";
				return compact('result', 'admin');
			} else {
				return compact('admin');
			}
        }
    }

	public function edit() {
		$session = Sessions::find($this->request->id);

		if (!$session) {
			return $this->redirect('Sessions::index');
		}
		if (($this->request->data) && $session->save($this->request->data)) {
			return $this->redirect(array('Sessions::view', 'args' => array($session->id)));
		}
		return compact('session');
	}

	public function delete() {
        Auth::clear('default');
        return $this->redirect('/');
    }
}
?>